/**
 * Created by Dalyn on 2017/2/28.
 */
import React from "react";
import Confirm from "../../common/Confirm"
import InputBox from "../../common/InputBox"
import './css/CompanyManage.css'
import {hashHistory} from 'react-router';
import GetEnterpriseListMutation from './mutation/GetEnterpriseListMutation'
import Relay from "react-relay";
import CompanyDetail from './CompanyDetail'
import Util from "../../util/Util";
import { Modal,message } from 'antd';

import {_Icon} from 'ANT_DE';
const Icon = _Icon;
/*信息列表*/

/*导出组件*/
export default class CompanyManage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            userName: '',
            enterpriseName: '',
        };
        this.Style = {}
        this.pageNum = 1;
        this.pageSize = 10;
        this.status = "";
    }


    serchenterprize(pageNum, pageSize) {
        Relay.Store.commitUpdate(
            new GetEnterpriseListMutation({
                //放传给后台参数的地方
                pageNum: pageNum,
                pageSize: pageSize,
                enterpriseName: this.refs.search_enterprize.state.text
            }),
            {
                onFailure: () => {
                },
                onSuccess: (response) => {
                    let data = response.getEnterpriseList.data;
                    this.refs.companydetail.setState({
                        companyArr: data.enterpriseList,
                        totalresult: data.totalResult
                    })

                }
            });

        this.setState({
            enterpriseName: this.refs.search_enterprize.state.text
        })
    }

    serchenterprizebyname() {
        // debugger
        let searchtext = this.refs.search_enterprize.state.text;
        let reg1 = /[%_\x22]+/;

        if (reg1.test(searchtext)) {
            message.info('不能输入%_特殊字符');
            return;
        }
        this.refs.companydetail.refs.pagination.setState({
            text: 1
        })
        this.serchenterprize(1, 10);
    }

    //asdasd
    componentWillMount() {
    }
    componentDidMount() {
        this.Style = {
            p_title: {
                width: "100%",
                height: 57,
                borderBottom: "1px #ededed solid"
            },
            inputsearch: {
                backgroundColor: 'red',
                height:10,
                width: 200,
                borderWidth: '0px'
            },
            new_Company: {
                width: 130,
                height: 30,
                fontSize: '14px'
            }
        };
        this.serchenterprize(1, 10);

    }


    bluron(){
        let searchtext = this.refs.search_enterprize.state.text;
        let reg1 = /^[%_\x22]+$/;

        if (reg1.test(searchtext)) {
            message.info('不能输入%_特殊字符');
            return;
        }
    }

    createPart() {
        hashHistory.push('/CreateCompany')
    }

    //asdasdsdasdasdasdasdasdasd
    render() {
        return (
            <div className="comManage_main">
                {/*企业列表*/}
                <div className="div_context">
                    <div className="companyDetail_title1">
                        {/*搜索框*/}
                        <span className="company_input_title"> 企业名称 </span>
                        <div className="coManage_search_en">
                            <InputBox style={this.Style.inputsearch} className="coManage_search_input" ref="search_enterprize"
                                      space="10" />

                            <span className="inputsearch_icon_en"
                                  onClick={this.serchenterprizebyname.bind(this)}>
                               <Icon type="search" />
                                搜索
                            </span>
                        </div>
                        <div className="new_Company_father_en"  style={!Util.authorityCheck("company") ? {display: 'none'} :{}}>
                            <Confirm tcontext={'新建企业'} className="company_btn-tit" style={{backgroundColor:"#a0d468",marginLeft:"-160px",marginTop:"-20px",color:"#fff",width:"120px",height:"35px"}} touch={this.createPart.bind(this)}></Confirm>
                        </div>
                    </div>
                    <CompanyDetail ref={'companydetail'} enterpriseName={this.state.enterpriseName}></CompanyDetail>
                </div>
            </div>
        )
    }
}
